package com.cc2019.buke.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.cc2019.buke.R;
import com.cc2019.buke.home.entry.Product;

import java.util.List;


public class QgAdapter extends RecyclerView.Adapter {

    List<Product> pro_list;
    Context context;

    public QgAdapter(Context context, List<Product> pro_list){
        this.pro_list = pro_list;
        this.context = context;
    }

    class QgHolder extends RecyclerView.ViewHolder{
        ImageView imageView;
        TextView textView;

        public QgHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.item_qgimg);
            textView = itemView.findViewById(R.id.item_qgname);
        }
        public void setData(int position){
            Product product = pro_list.get(position);
            imageView.setImageResource(product.getImgId());
            textView.setText(product.getName());
        }

    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.home_qg_layout,parent,false);
        return new QgHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView. ViewHolder holder, int position) {
        QgHolder qgHolder = (QgHolder)holder;
        qgHolder.setData(position);

    }

    @Override
    public int getItemCount() {
        return pro_list.size();
    }
}
